package com.java46.carera.stock.enterstock.service;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.java46.carera.base.entity.vo.PutStorageVo;
import com.java46.carera.base.exception.BusinessException;
import com.java46.carera.base.mapper.PutStorageMapper;
import com.java46.carera.base.mapper.RepertoryMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.java46.carera.base.entity.PutStorage;

import java.util.List;

/**
 * @ClassName EnterStockService
 * @Description TODO
 * @Author Administrator
 * @Date 2018/8/23 0023 19:42
 * @Vcrsion 1.0
 **/
@Service
public class EnterStockService {

    @Autowired
    private PutStorageMapper putStorageMapper;

    @Autowired
    private RepertoryMapper repertoryMapper;



    /**
     * @Author xiao
     * @Description //分页查询入库记录可关键字查询
     * @Date 22:28 2018/8/23 0023
     * @Param [pageNum, pageSize, keywords]
     * @return com.github.pagehelper.PageInfo<com.java46.carera.base.entity.vo.PutStorageVo>
     */
    public PageInfo<PutStorageVo> queryEnterStock(int pageNum, int pageSize, String keywords) throws Exception {

        PageHelper.startPage(pageNum,pageSize);
        List<PutStorageVo> repertories = putStorageMapper.selectAll(keywords);
        if (repertories.isEmpty()){
            throw new BusinessException("没有查询到信息");
        }
        PageInfo<PutStorageVo> pages = new PageInfo<>(repertories);
        return pages;
    }


    /**
     * @Author xiao
     * @Description //新增入库记录
     * @Date 22:51 2018/8/23 0023
     * @Param [putStorage]
     * @return void
     */
    public void insertEnterStock(PutStorage putStorage) throws Exception {

        if(putStorage==null){
            throw new BusinessException("没有任何入库信息");
        }
        putStorageMapper.insertPutStorage(putStorage);
        repertoryMapper.updateEnterRepNum(putStorage.getNumber(),putStorage.getRepid());
    }

    /**
     * @Author xiao
     * @Description //通过入库编号删除入库记录
     * @Date 22:51 2018/8/23 0023
     * @Param [putId]
     * @return void
     */
    public void deleteEnterStock(Integer putId) throws Exception {

        if(putId==null){
            throw new BusinessException("没有任何入库信息");
        }
        putStorageMapper.deleteByPutId(putId);
    }


}
